//----------------------------------------------------------------------------//
// I N C L U D E   Q T                                                        //
//----------------------------------------------------------------------------//


//----------------------------------------------------------------------------//
// I N C L U D E   P R O J E C T                                              //
//----------------------------------------------------------------------------//
#include "movie.h"


//----------------------------------------------------------------------------//
// M A C R O S                                                                //
//----------------------------------------------------------------------------//


//----------------------------------------------------------------------------//
// T Y P E S   &   D E F I N I T I O N S                                      //
//----------------------------------------------------------------------------//


//----------------------------------------------------------------------------//
// C O N T R U C T O R S                                                      //
//----------------------------------------------------------------------------//
/** Constructor
 *
 * QString    title             movie title
 * MovieDub_t dub               movie dubbing
 * Movie3D_t  threedim          movie display type
 * QString    duration          movie duration in format (23h05)
 * QString    poster            movie poster url
 */
Movie::Movie(QString    title,
             QString    duration)
{
  Title    = title;
  Duration = QTime::fromString(duration, "hh'h'mm");

  Selected       = MOVIE_NOT_SELECTED;

  UrlIMDb = QUrl("");
  RateIMDb = 0;
  UrlAllocine = QUrl("");
  RateAllocine = 0;
}


//----------------------------------------------------------------------------//
// P U B L I C   M E T H O D S                                                //
//----------------------------------------------------------------------------//
/** Setter
 */
void Movie::setSelectedDub(MovieDub_t& dub)
{
  DubSelected = dub;
}
void Movie::setSelected3D(Movie3D_t& threedim)
{
  ThreeDSelected = threedim;
}
void Movie::setUrlIMDb(QString& url)
{
  UrlIMDb = QUrl(url);
}
void Movie::setRateIMDb(QString& rate)
{
  RateIMDb = rate.toFloat();
}
void Movie::setUrlAllocine(QString& url)
{
  UrlAllocine = QUrl(url);
}
void Movie::setRateAllocine(QString& rate)
{
  RateAllocine = rate.toFloat();
}
void Movie::setPoster(QString& url)
{
  Poster = QUrl(url);
}

/** Getter
 */
QString Movie::getTitle(void)
{
  return (Title);
}
QTime Movie::getDuration(void)
{
  return (Duration);
}
MovieDub_t Movie::getDubSelected(void)
{
  return (DubSelected);
}
Movie3D_t Movie::get3DSelected(void)
{
  return (ThreeDSelected);
}
QUrl Movie::getPoster(void)
{
  return (Poster);
}
QUrl Movie::getUrlIMDb(void)
{
  return (UrlIMDb);
}
float Movie::getRateIMDb(void)
{
  return (RateIMDb);
}
QUrl Movie::getUrlAllocine(void)
{
  return (UrlAllocine);
}
float Movie::getRateAllocine(void)
{
  return (RateAllocine);
}

/** Operator of comparison ==
 */
bool Movie::operator==(Movie &right)
{
  return (Title == right.getTitle());
}

/** Add time in timetable
 *
 * Theater* thtr        Theater of the timetable
 * QTime&   time        TimeTable to add
 */
void Movie::addTimeTable(Theater*&   thtr,
                         QDate&      date,
                         MovieDub_t& dub,
                         Movie3D_t&  threeD,
                         QTime&      time)
{
  TimeTable* timeTableTmp;
  int        index = 0;


  // time exists but with same data ?
  foreach (TimeTable* tt, Times)
  {
    if (tt->isDifferent(thtr, date, dub, threeD, time))
    {
      index++;
    }
  }

  // when none of TimeTable has same data
  if (index == Times.length())
  {
    // create a new TimeTable
    timeTableTmp = new TimeTable(time);

    // set values of TimeTable
    timeTableTmp->setTheater(thtr);
    timeTableTmp->setDate(date);
    timeTableTmp->setDub(dub);
    timeTableTmp->set3D(threeD);

    // add new time in timetable
    Times << timeTableTmp;
  }
}

/** remove timetable of the theater
 *
 * Theater* thtr        Theater of the timetable
 *
 * return TRUE when the theater was found
 */
bool Movie::removeTimeTable(Theater *thtr)
{
  int  index  = 0;
  bool status = FALSE;

  for (index = 0; index < Times.length(); index++)
  {
    // when the name theater matches
    if (Times[index]->getTheater()->getName() == thtr->getName())
    {
      // remove the timetable
      Times.removeAt(index);
      status = TRUE;
      break;
    }
  }

  return (status);
}


//----------------------------------------------------------------------------//
// S L O T S                                                                  //
//----------------------------------------------------------------------------//


//----------------------------------------------------------------------------//
// P R I V A T E   M E T H O D S                                              //
//----------------------------------------------------------------------------//


//----------------------------------------------------------------------------//
// G L O B A L E S   F U N C T I O N S   D E C L A R A T I O N                //
//----------------------------------------------------------------------------//


//----------------------------------------------------------------------------//
// P R I V A T E S   F U N C T I O N S   D E C L A R A T I O N                //
//----------------------------------------------------------------------------//
